﻿using System;
using System.Collections;
using System.Collections.Generic;
using eCommerce.Core.Domain.Pictures;

namespace eCommerce.Core.Domain.Products
{
    public class Item:BaseEntity
    {
        public virtual int ProductId { get; set; }
        public virtual Product Product { get; set; }

        public virtual int ItemGroupId { get; set; }
        public virtual ItemGroup ItemGroup { get; set; }

        public virtual string ItemGroupCode { get; set; }

        public virtual decimal Price { get; set; }

        public virtual int StockQuantity { get; set; }


        /// <summary>
        /// Gets or sets the date and time of instance creation
        /// </summary>
        public virtual DateTime CreatedOn{ get; set; }

        /// <summary>
        /// Gets or sets the date and time of instance update
        /// </summary>
        public virtual DateTime UpdatedOn{ get; set; }

        /// <summary>
        /// Gets or sets the display order
        /// </summary>
        public virtual int DisplayOrder { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the entity is published
        /// </summary>
        public virtual bool Published { get; set; }
        public virtual bool Deleted { get; set; }


        //public virtual int? IconPictureId { get; set; }
        //public virtual Picture IconPicture { get; set; }


      

        public virtual int? ProductAttributeValueId{ get; set; }
        public virtual ProductAttributeValue ProductAttributeValue{ get; set; }

        public virtual int? ItemAttributeValueId { get; set; }
        public virtual ItemAttributeValue ItemAttributeValue { get; set; }

        public string ToDescription()
        {
            var productName = this.Product.ProductName;
            var productAttributeDescription= this.ProductAttributeValue != null
                ? String.Format("{0}:{1}", this.ProductAttributeValue.ProductAttributeKey.Name, this.ProductAttributeValue.Value )
                : string.Empty;
            var itemAttributeDescription = this.ItemAttributeValue != null
                ? String.Format("{0}:{1}",this.ItemAttributeValue.ItemAttributeKey.Name, this.ItemAttributeValue.Value )
                : string.Empty;

            return string.Format("{0}{1}{2}", productName,
                !string.IsNullOrEmpty(productAttributeDescription) ? " " + productAttributeDescription : string.Empty,
                !string.IsNullOrEmpty(itemAttributeDescription) ? " " + itemAttributeDescription : string.Empty);

        }

    }
}